const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  context: path.join(__dirname, "src"),
  entry: ["./js/index.js", "./js/lib/dragonBones.js"],
  output: {
    filename: "main[fullhash:4].js",
    path: path.resolve(__dirname, "dist"),
    clean: true
  },
  performance: {
    hints: false
  },
  devServer: {
    static: {
      directory: path.join(__dirname, "src")
    },
    compress: true,
    port: 9000,
    host: "0.0.0.0",
    open: ["./index.html"]
  },
  mode: "production",
  target: "web",
  plugins: [
    new CopyWebpackPlugin({
      patterns: [{ from: "assets", to: "assets" }],
      options: {
        concurrency: 100
      }
    }),
    new HtmlWebpackPlugin({
      template: "./index.html"
    })
  ],
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"]
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: "asset/resource"
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        type: "asset/resource"
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
};
